﻿/********************************************************************************
** 作者： 李丽艳
** 创建时间： 2010-6-24
** 描述：
** 绑定菜单树-涉及到的相关方法
********************************************************************************/
var ActionID = "";

Ext.InfoLoader = Ext.extend(Ext.tree.TreeLoader,
         {
             tempvalue: null,
             createNode: function(attr) {
                 // apply baseAttrs, nice idea Corey!
                 if (this.tempvalue != null && this.tempvalue != "") {
                     var tempArray = this.tempvalue.split(",");
                     Ext.each(tempArray, function(n) {
                         if (attr["id"] == n) {

                             attr["checked"] = true;
                         }
                     }, this);
                 }
                 if (this.baseAttrs) {
                     Ext.applyIf(attr, this.baseAttrs);
                 }
                 if (this.applyLoader !== false) {
                     attr.loader = this;
                 }
                 if (typeof attr.uiProvider == 'string') {
                     attr.uiProvider = this.uiProviders[attr.uiProvider] || eval(attr.uiProvider);
                 }
                 if (attr.nodeType) {
                     return new Ext.tree.TreePanel.nodeTypes[attr.nodeType](attr);
                 } else {
                     return attr.leaf ?
                                new Ext.tree.TreeNode(attr) :
                                new Ext.tree.AsyncTreeNode(attr);
                 }
             }
         });


function ShowRoleMenuWin(BindValue, RoleID, strTitle) {
  
    var rootNodeTrade =  new Ext.tree.AsyncTreeNode({
    id   : '-1',
    text : '所有菜单'
    }); 
  
    //var rootNodeTrade = { nodeType: 'async', text: '所有权限', draggable: false, id: 'TreeAll', collapsed: false, expanded: true };
    // 定义树对象
    var TradeTree = new Ext.tree.TreePanel(
         {
             columnWidth: 1,
             id: 'treeTrade',
             margins: '2 2 0 2',
             autoScroll: true,
             root: rootNodeTrade,
             height: 209,
             width: 203,
             singleExpand: false,
             checkModel: "childCascade",  // 对树的级联多选
             onlyLeafCheckable: false,   // 对树所有结点都可选
             loader: new Ext.InfoLoader(
              {
                  dataUrl: strPath + 'SystemManage/GetMenuTree.aspx',
                  tempvalue: BindValue,
                  baseAttrs:
                 {
                     uiProvider: Ext.ux.TreeCheckNodeUI
                 }
              }
             ), listeners: {
                 'load': loadHandler
             }
         }
        );

    winHbDepartMent = new Ext.Window({
        title: '&nbsp;' + strTitle,
        width: 420,
        height: 450,
        layout: 'fit',
        id: 'winHbDepartMent',
        plain: true,
        closeAction: 'close',
        modal: true,
        deferredRender: false,
        bodyStyle: 'padding:5px;',
        buttonAlign: 'center',
        items: TradeTree,
        buttons: [{
            text: '确定',
            id: 'btnTreeInfo',
            name: 'btnTreeInfo',
            handler: function() {
                var checkText = new Array;
                var checkId = new Array;
                var len = TradeTree.getChecked();
                for (var i = 0; i < len.length; i++) {
                    if (len[i].getDepth() < 1) continue;
                    // if(len[i].id =='TreeAll') continue;
                    checkId.push(len[i].id);
                }
                  MenuID = checkId.toString();
                  UpdateRoleAction(RoleID, MenuID);
                  winHbDepartMent.close();
            }
        }, {
            text: '关闭',
            handler: function() {
                winHbDepartMent.close();
            }
}]
        });
        winHbDepartMent.show();
        var myMask = new Ext.LoadMask('winHbDepartMent', {
            msg: "正在加载数据...",
            removeMask: true
        });
        myMask.show();

        TradeTree.expandAll(); //expandPath('/TreeAll/', false);

        function loadHandler(Node) { // 加载后事件响应处理
            // if (Node.isLast() && Node.getDepth() == '1')
            myMask.hide();
        }
    }


    function ShowUserMenuWin(BindValue, UserID, strTitle) {

        var rootNodeTrade = new Ext.tree.AsyncTreeNode({
            id: '-1',
            text: '所有菜单'
        });

        //var rootNodeTrade = { nodeType: 'async', text: '所有权限', draggable: false, id: 'TreeAll', collapsed: false, expanded: true };
        // 定义树对象
        var TradeTree = new Ext.tree.TreePanel(
         {
             columnWidth: 1,
             id: 'treeTrade',
             margins: '2 2 0 2',
             autoScroll: true,
             root: rootNodeTrade,
             height: 209,
             width: 203,
             singleExpand: false,
             checkModel: "childCascade",  // 对树的级联多选
             onlyLeafCheckable: false,   // 对树所有结点都可选
             loader: new Ext.InfoLoader(
              {
                  dataUrl: strPath + 'SystemManage/GetMenuTree.aspx',
                  tempvalue: BindValue,
                  baseAttrs:
                 {
                     uiProvider: Ext.ux.TreeCheckNodeUI
                 }
              }
             ), listeners: {
                 'load': loadHandler
             }
         }
        );

        winHbDepartMent = new Ext.Window({
            title: '&nbsp;' + strTitle,
            width: 420,
            height: 450,
            layout: 'fit',
            id: 'winHbDepartMent',
            plain: true,
            closeAction: 'close',
            modal: true,
            deferredRender: false,
            bodyStyle: 'padding:5px;',
            buttonAlign: 'center',
            items: TradeTree,
            buttons: [{
                text: '确定',
                id: 'btnTreeInfo',
                name: 'btnTreeInfo',
                handler: function() {
                    var checkText = new Array;
                    var checkId = new Array;
                    var len = TradeTree.getChecked();
                    for (var i = 0; i < len.length; i++) {
                        if (len[i].getDepth() < 1) continue;
                        // if(len[i].id =='TreeAll') continue;
                        checkId.push(len[i].id);
                    }
                    MenuID = checkId.toString();
                    UpdateUserAction(UserID, MenuID);
                    winHbDepartMent.close();
                }
            }, {
                text: '关闭',
                handler: function() {
                    winHbDepartMent.close();
                }
}]
            });
            winHbDepartMent.show();
            var myMask = new Ext.LoadMask('winHbDepartMent', {
                msg: "正在加载数据...",
                removeMask: true
            });
            myMask.show();

            TradeTree.expandAll(); //expandPath('/TreeAll/', false);

            function loadHandler(Node) { // 加载后事件响应处理
                if (Node.isLast() && Node.getDepth() == '1')
                myMask.hide();
            }
        }